home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue45 / DCOM / DemoClient / testDemoAutoobju.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1998-09-17  |  2.6 KB  |  92 lines

  1. unit testDemoAutoobju;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls,Demoauto_TLB;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Button1: TButton;
  12.     Button2: TButton;
  13.     procedure Button1Click(Sender: TObject);
  14.     procedure Button2Click(Sender: TObject);
  15.     procedure FormCreate(Sender: TObject);
  16.   private
  17.     { Private declarations }
  18.   public
  19.     { Public declarations }
  20.   end;
  21.  
  22. CoDispDemoAutoObj = class
  23.   class function Create: IDemoAutoObjDisp;
  24.   class function CreateRemote(const MachineName: string): IDemoAutoObjDisp;
  25. end;
  26.  
  27. var
  28.   Form1: TForm1;
  29.  
  30. implementation
  31.  
  32.  
  33. {$R *.DFM}
  34.  
  35. uses ComObj,ActiveX, CreateRem, DCOMSecUtils;
  36.  
  37. class function CoDispDemoAutoObj.Create: IDemoAutoObjDisp;
  38. begin
  39.  Result := IDemoAutoObjDisp(CreateComObject(Class_DemoAutoObj) as IDispatch);
  40. end;
  41.  
  42. class function CoDispDemoAutoObj.CreateRemote(const MachineName: string): IDemoAutoObjDisp;
  43. begin
  44.   Result := IDemoAutoObjDisp(CreateRemoteComObject(MachineName, Class_DemoAutoObj) as IDispatch);
  45. end;
  46.  
  47. procedure TForm1.Button1Click(Sender: TObject);
  48. var
  49.  ADemoAutoObj : IDemoAutoObjDisp;
  50. begin
  51.   SwitchSecurityOff(false);
  52.   ADemoAutoObj := IDemoAutoObjDisp(CreateRemComObject('OBELIX',
  53.                                          Class_DemoAutoObj, IDispatch));
  54.   OleCheck(CoSetProxyBlanket(ADemoAutoObj,
  55.                             RPC_C_AUTHN_WINNT,
  56.                             RPC_C_AUTHZ_NONE,
  57.                             nil,
  58.                             RPC_C_AUTHN_LEVEL_CONNECT,
  59.                             RPC_C_IMP_LEVEL_IMPERSONATE,
  60.                             nil,
  61.                             0));
  62.   //CoDispDemoAutoObj.CreateRemote('Obelix');
  63.   Caption := ADemoAutoObj.AMessage;
  64. end;
  65.  
  66. procedure TForm1.Button2Click(Sender: TObject);
  67. var
  68.  ADemoAutoObj :IDemoAutoObj;
  69. begin
  70.  SwitchSecurityOff(false);
  71.  ADemoAutoObj := IDemoAutoObj(CreateRemComObject('Obelix',
  72.                                          Class_DemoAutoObj, IDemoAutoObj));
  73.  //CoDemoAutoObj.CreateRemote('Obelix');
  74.  Caption := ADemoAutoObj.AMessage;
  75. end;
  76.  
  77. //{$R DemoAuto.tlb}
  78.  
  79. procedure TForm1.FormCreate(Sender: TObject);
  80. var
  81.  pTypeLib : ITypeLib;
  82. begin
  83.  //OleCheck(...) requires COMObj to be in the uses clause
  84.  //LoadTypeLibEx(...) requires ActiveX to be in the uses clause
  85.  //uses ComObj,ActiveX;
  86.  //OleCheck(LoadTypeLibEx('EmptyDLL.DLL',REGKIND_REGISTER, pTypeLib));
  87.  //OleCheck(LoadTypeLibEx(StringToOLEStr(Application.ExeName),REGKIND_REGISTER, pTypeLib))
  88. // OleCheck(LoadTypeLibEx('DemoAuto.tlb',REGKIND_REGISTER, pTypeLib));
  89. end;
  90.  
  91. end.
  92.